import { RouteRecordRaw } from "vue-router";

/**
 * 动态路由|异步路由
 */
export const asyncRoutes: RouteRecordRaw[] = [
  {
    path: "/acl",
    name: "acl",
    component: () => import("@/layout/index.vue"),
    meta: {
      title: "权限管理",
      icon: "Operation",
      requiresAuth: true,
    },
    children: [
      {
        path: "/acl/user",
        name: "user",
        component: () => import("@/views/acl/user/index.vue"),
        meta: {
          title: "用户管理",
          icon: "User",
        },
      },
      {
        path: "/acl/role",
        name: "role",
        component: () => import("@/views/acl/role/index.vue"),
        meta: {
          title: "角色管理",
          icon: "Avatar",
        },
      },
      {
        path: "/acl/menu",
        name: "menu",
        component: () => import("@/views/acl/menu/index.vue"),
        meta: {
          title: "菜单管理",
          icon: "View",
        },
      },
    ],
  },
  {
    path: "/contract",
    name: "contract",
    component: () => import("@/layout/index.vue"),
    meta: {
      title: "合同管理",
      icon: "OfficeBuilding",
      requiresAuth: true,
    },
    redirect: "/contract/conpanys",
    children: [
      {
        path: "/contract/conpanys",
        component: () => import("@/views/contract/companys/index.vue"),
        name: "conpanys",
        meta: {
          title: "公司管理",
          icon: "OfficeBuilding",
        },
      },
      {
        path: "/contract/employees",
        component: () => import("@/views/contract/employees/index.vue"),
        name: "employees",
        meta: {
          title: "员工管理",
          icon: "User",
        },
      },
      {
        path: "/contract/exportExcel",
        component: () => import("@/views/contract/exportExcel/index.vue"),
        name: "exportExcel",
        meta: {
          title: "导出表格",
          icon: "User",
        },
      },
    ],
  },
];

/**
 * 常量|静态路由
 */
export const constantRoutes: RouteRecordRaw[] = [
  {
    path: "/login",
    name: "login",
    meta: {
      title: "登录",
      hidden: true,
    },
    component: () => import("@/views/login/index.vue"),
  },
  {
    path: "/",
    name: "layout",
    meta: {
      title: "",
      icon: "Avatar",
      hidden: true,
    },
    component: () => import("@/layout/index.vue"),
    redirect: "/home",
    children: [
      {
        path: "/home",
        name: "home",
        meta: {
          title: "首页",
          icon: "House",
        },
        component: () => import("@/views/home/index.vue"),
      },
    ],
  },
  {
    path: "/screen",
    component: () => import("@/views/screen/index.vue"),
    name: "screen",
    meta: {
      title: "数据大屏",
      icon: "Monitor",
    },
  },

  {
    path: "/404",
    component: () => import("@/views/404/vue404.vue"),
    name: "404",
    meta: {
      title: "404",
      hidden: true,
    },
  },
];

/**
 * 任意路由
 */
export const anyRoutes: RouteRecordRaw[] = [
  {
    path: "/:pathMath(.*)*",
    redirect: "/404",
    name: "any",
    meta: {
      title: "任意路由",
      hidden: true,
    },
  },
];

export function filterAsyncRoutes(
  asyncRoute: RouteRecordRaw[],
  routes: string[]
) {
  return asyncRoute.filter(item => {
    if (routes.includes(item.name as string)) {
      if (item.children && item.children.length > 0) {
        item.children = filterAsyncRoutes(item.children, routes);
      }
      return true;
    }
  });
}
